﻿package com.view 
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.ui.Mouse;
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author zheng sir
	 */
	public class MouseMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "mouseMediator";
		public static const SHOW_MOUSE:String = "mouseMediator_show";
		public static const HIDE_MOUSE:String = "mouseMediator_hide";
		public static const MOUSECHANGED:String = "mouseMediator_changed";//鼠标图标改变
		public static const CHANGEDNUM:String = "mouseMediator_changedNum";//使用哪个颜色？
		public static const PLAY:String = "mouseMediator_play";//播放动画
		
		public function MouseMediator(mediatorName:String = null, viewComponent:Object = null) 
		{
			super(mediatorName, viewComponent);
			
		}
		override public function onRegister():void 
		{
			super.onRegister();
			delMouseEnable(viewComponent.mouseHolder);
		}
		override public function listNotificationInterests():Array 
		{
			return [MOUSECHANGED,SHOW_MOUSE,HIDE_MOUSE,CHANGEDNUM,PLAY];
		}
		override public function handleNotification(notification:INotification):void 
		{
			super.handleNotification(notification);
			var name:String = notification.getName();
			var stage:Stage = facade.retrieveMediator(ApplicationMediator.NAME).getViewComponent().stage as Stage;
			switch(name) {
				case SHOW_MOUSE:
					stage.addChild(viewComponent.mouseHolder);
					MovieClip(viewComponent.mouseHolder).startDrag(true);
					//Mouse.hide();
					break;
				case HIDE_MOUSE:
					stage.removeChild(viewComponent.mouseHolder);
					MovieClip(viewComponent.mouseHolder).stopDrag();
					//Mouse.show();
					break;
				case MOUSECHANGED:
					var num:int = notification.getBody() as int;//现在选择的是什么工具
					if (MovieClip(viewComponent.mouseHolder).numChildren) {
						MovieClip(viewComponent.mouseHolder).removeChildAt(0);
					}
					switch(num) {
						case 1:
							var eyeTool:MovieClip = new EyeTool();
							eyeTool.stop();
							MovieClip(eyeTool.getChildAt(0)).stop();
							viewComponent.mouseHolder.addChild(eyeTool);
							break;
						case 2:
							var eyeShadowTool:MovieClip = new EyeShadowTool();
							eyeShadowTool.stop();
							MovieClip(eyeShadowTool.getChildAt(0)).stop();
							viewComponent.mouseHolder.addChild(eyeShadowTool);
							break;
						case 3:
							var blushTool:MovieClip = new BlushTool();
							blushTool.stop();
							MovieClip(blushTool.getChildAt(0)).stop();
							viewComponent.mouseHolder.addChild(blushTool);
							break;
						case 4:
							var eyelashTool:MovieClip = new EyelashTool();
							eyelashTool.stop();
							MovieClip(eyelashTool.getChildAt(0)).stop();
							viewComponent.mouseHolder.addChild(eyelashTool);
							break;
						case 5:
							var rougeMc:MovieClip = new RougeMc();
							rougeMc.stop();
							MovieClip(rougeMc.getChildAt(0)).stop();
							viewComponent.mouseHolder.addChild(rougeMc);
							break;
					}
					break;
				case CHANGEDNUM:
					var colorNum:int = notification.getBody() as int;
					MovieClip(viewComponent.mouseHolder.getChildAt(0)).gotoAndStop(colorNum);
					break;
				case PLAY:
					MovieClip(viewComponent.mouseHolder.getChildAt(0).getChildAt(0)).play();
			}
		}
		private function delMouseEnable(mc:MovieClip):void {
			mc.mouseChildren = false;
			mc.mouseEnabled = false;
		}
	}

}